﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.IO;

/// <summary>
///ErrorLog 的摘要说明
/// </summary>
public class ErrorLog
{
    public ErrorLog()
    {
        //
        //TODO: 在此处添加构造函数逻辑
        //
    }
    /// 记录日志至文本文件 /// /// 记录的内容 
    public static void Log(string Path, string message)
    {

        //新建文件夹
        if (!Directory.Exists(Path))
        {
            Directory.CreateDirectory(Path);
        }
        Random rd = new Random();
        string FILE_NAME = Path + "/" + DateTime.Now.ToString("yyyyMMdd") + ".txt";
        if (!File.Exists(FILE_NAME))
        {
            StreamWriter sr = File.CreateText(FILE_NAME);
            sr.Close();
        }

        using (StreamWriter sr = File.AppendText(FILE_NAME))
        {
            lock (sr)
            {
                sr.WriteLine(message);
                sr.Close();
            }
        }
    }
    /// 记录日志至文本文件 /// /// 记录的内容 
    public static void Log2(string Path, string message)
    {

        //新建文件夹
        if (!Directory.Exists(Path))
        {
            Directory.CreateDirectory(Path);
        }
        Random rd = new Random();
        string FILE_NAME = Path + "/" + DateTime.Now.ToString("yyyyMMddHHmmss")+"_"+new Random().Next(1000,9999) + ".txt";
        if (!File.Exists(FILE_NAME))
        {
            StreamWriter sr = File.CreateText(FILE_NAME);
            sr.Close();
        }

        using (StreamWriter sr = File.AppendText(FILE_NAME))
        {
            lock (sr)
            {
                sr.WriteLine(message);
                sr.Close();
            }
        }
    }
}
